﻿using DeviceDebugger.DataAccess;
using DeviceDebugger.Model;
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceDebugger.Common
{
    public class ApplicationStore : ObservableObject
    {
        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;//静态事件处理属性更改

        private static ObservableDictionary<string, ProtocolModel> _dicProtocol;

        /// <summary>
        /// 存储所有点
        /// </summary>
        public static ObservableDictionary<string, ProtocolModel> DicProtocol
        {
            get { return _dicProtocol; }
            set
            {
                _dicProtocol = value;
                StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(DicProtocol)));
            }
        }

        private static StackerModel _currentStacker;
        /// <summary>
        /// 当前调试的堆垛机
        /// </summary>
        public static StackerModel CurrentStacker
        {
            get { return _currentStacker; }
            set { _currentStacker = value; StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(CurrentStacker))); }
        }


        public ApplicationStore()
        {
            DicProtocol = new();
            DataVisitor.GetProtocols().ForEach(a => DicProtocol.Add(a.Name, a));
        }

        /// <summary>
        /// 重新加载点位字典
        /// </summary>
        private void ReloadDic()
        {
            DicProtocol.Clear();
            DataVisitor.GetProtocols().ForEach(a => DicProtocol.Add(a.Name, a));

        }
    }
}
